package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.OutsTaskDistrMainDao;
import com.fdb.efp.nls.service.domain.OutsTaskDistrMain;
import com.fdb.efp.nls.service.facade.OutsTaskDistrMainService;
import com.fdb.efp.nls.service.vo.OutsTaskDistrMainVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 委外任务分配主表 <p>
 * @author ligm
 * @date 2019-08-27
 */
@Service("outsTaskDistrMainService")
public class OutsTaskDistrMainServiceImpl implements OutsTaskDistrMainService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(OutsTaskDistrMainServiceImpl.class);

	@Autowired
	private OutsTaskDistrMainDao outsTaskDistrMainDao;
	
	/**
	 * 新增操作
	 */
	public int insertOutsTaskDistrMain(OutsTaskDistrMainVO inOutsTaskDistrMainVo) {
		logger.debug("当前新增数据为:"+ inOutsTaskDistrMainVo.toString());
		int num = 0;
		try {
			OutsTaskDistrMain outsTaskDistrMain = new OutsTaskDistrMain();
			beanCopy(inOutsTaskDistrMainVo, outsTaskDistrMain);
			num = outsTaskDistrMainDao.insertOutsTaskDistrMain(outsTaskDistrMain);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(OutsTaskDistrMainVO inOutsTaskDistrMainVo) {
		logger.debug("当前删除数据条件为:"+ inOutsTaskDistrMainVo.toString());
		int num = 0;
		try {
			OutsTaskDistrMain outsTaskDistrMain = new OutsTaskDistrMain();
			beanCopy(inOutsTaskDistrMainVo, outsTaskDistrMain);
			num = outsTaskDistrMainDao.deleteByPk(outsTaskDistrMain);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inOutsTaskDistrMainVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(OutsTaskDistrMainVO inOutsTaskDistrMainVo) {
		logger.debug("当前修改数据为:"+ inOutsTaskDistrMainVo.toString());
		int num = 0;
		try {
			OutsTaskDistrMain outsTaskDistrMain = new OutsTaskDistrMain();
			beanCopy(inOutsTaskDistrMainVo, outsTaskDistrMain);
			num = outsTaskDistrMainDao.updateByPk(outsTaskDistrMain);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inOutsTaskDistrMainVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public OutsTaskDistrMainVO queryByPk(OutsTaskDistrMainVO inOutsTaskDistrMainVo) {
		
		logger.debug("当前查询参数信息为:"+ inOutsTaskDistrMainVo);
		try {
			OutsTaskDistrMain queryOutsTaskDistrMain = new OutsTaskDistrMain();
			beanCopy(inOutsTaskDistrMainVo, queryOutsTaskDistrMain);
			OutsTaskDistrMain queryRslOutsTaskDistrMain = outsTaskDistrMainDao.queryByPk(queryOutsTaskDistrMain);
			if (Objects.nonNull(queryRslOutsTaskDistrMain)) {
				OutsTaskDistrMainVO outOutsTaskDistrMainVo = beanCopy(queryRslOutsTaskDistrMain, new OutsTaskDistrMainVO());
				logger.debug("当前查询结果为:"+ outOutsTaskDistrMainVo.toString());
				return outOutsTaskDistrMainVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<OutsTaskDistrMainVO> queryAllOwner(OutsTaskDistrMainVO outsTaskDistrMainVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<OutsTaskDistrMainVO> list = null;
		try {
			List<OutsTaskDistrMain> outsTaskDistrMains = outsTaskDistrMainDao.queryAllOwnerByPage(outsTaskDistrMainVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ outsTaskDistrMains.size());
			pageSet(outsTaskDistrMains, outsTaskDistrMainVo);
			list = (List<OutsTaskDistrMainVO>) beansCopy(outsTaskDistrMains, OutsTaskDistrMainVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<OutsTaskDistrMainVO> queryAllCurrOrg(OutsTaskDistrMainVO outsTaskDistrMainVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<OutsTaskDistrMain> outsTaskDistrMains = outsTaskDistrMainDao.queryAllCurrOrgByPage(outsTaskDistrMainVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+outsTaskDistrMains.size());
		List<OutsTaskDistrMainVO> list = null;
		try {
			pageSet(outsTaskDistrMains, outsTaskDistrMainVo);
			list = (List<OutsTaskDistrMainVO>) beansCopy(outsTaskDistrMains, OutsTaskDistrMainVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<OutsTaskDistrMainVO> queryAllCurrDownOrg(OutsTaskDistrMainVO outsTaskDistrMainVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<OutsTaskDistrMain> outsTaskDistrMains = outsTaskDistrMainDao.queryAllCurrDownOrgByPage(outsTaskDistrMainVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ outsTaskDistrMains.size());
		List<OutsTaskDistrMainVO> list = null;
		try {
			pageSet(outsTaskDistrMains, outsTaskDistrMainVo);
			list = (List<OutsTaskDistrMainVO>) beansCopy(outsTaskDistrMains, OutsTaskDistrMainVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

	@Override
	public int batchInsertVo(List<OutsTaskDistrMainVO> voLists) {
		int result = 0;
		logger.debug("批量插入的数据长度为：" + voLists.size());
		try {
			List<OutsTaskDistrMain> outsTaskDistrMainList = (List<OutsTaskDistrMain>) beansCopy(voLists, OutsTaskDistrMain.class);
			result = outsTaskDistrMainDao.batchInsertVo(outsTaskDistrMainList);
			logger.debug("批量成功插入的数据长度为：" + result);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			result = -1;
		}
		return result;
	}

	@Override
	public int updateByColltBatchNo(OutsTaskDistrMainVO updVo) {
		logger.debug("当前修改数据为:"+ updVo.toString());
		int num = 0;
		try {
			OutsTaskDistrMain outsTaskDistrMain = new OutsTaskDistrMain();
			beanCopy(updVo, outsTaskDistrMain);
			num = outsTaskDistrMainDao.updateByColltBatchNo(outsTaskDistrMain);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ updVo.toString() +"，修改的数据条数为"+ num);
		return num;
	}

	@Override
	public List<OutsTaskDistrMainVO> queryVoByColltBatchNo(OutsTaskDistrMainVO outsTaskDistrMainVo) {
		logger.debug("当前查询参数为:" + outsTaskDistrMainVo.toString());
		List<OutsTaskDistrMainVO> list = null;
		try {
			OutsTaskDistrMain outsTaskDistrMain = new OutsTaskDistrMain();
			beanCopy(outsTaskDistrMainVo, outsTaskDistrMain);
			List<OutsTaskDistrMain> outsTaskDistrMains = outsTaskDistrMainDao.queryVoByColltBatchNoByPage(outsTaskDistrMain);
			logger.debug("查询结果集数量为:"+ outsTaskDistrMains.size());
			pageSet(outsTaskDistrMains, outsTaskDistrMain);
			list = (List<OutsTaskDistrMainVO>) beansCopy(outsTaskDistrMains, OutsTaskDistrMainVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	@Override
	public List<OutsTaskDistrMainVO> queryAllByConditions(OutsTaskDistrMainVO outsTaskDistrMainVo) {
		logger.debug("当前查询参数为:" + outsTaskDistrMainVo.toString());
		List<OutsTaskDistrMainVO> list = null;
		try {
			OutsTaskDistrMain outsTaskDistrMain = new OutsTaskDistrMain();
			beanCopy(outsTaskDistrMainVo, outsTaskDistrMain);
			List<OutsTaskDistrMain> outsTaskDistrMains = outsTaskDistrMainDao.queryAllByConditionsByPage(outsTaskDistrMain);
			logger.debug("查询结果集数量为:"+ outsTaskDistrMains.size());
			pageSet(outsTaskDistrMains, outsTaskDistrMain);
			list = (List<OutsTaskDistrMainVO>) beansCopy(outsTaskDistrMains, OutsTaskDistrMainVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

}
